package com.misc.tunewsreader;

import android.util.Log;

public class NNTPGroup {
    private String name;
    private long high;
    private long low;

    public NNTPGroup(String line) {
	if (line == null)
	    return;

	String[] parts = line.split(" ");
	if (parts.length >= 1)
	    name = parts[0].trim();
	if (parts.length >= 2) {
	    try {
		high = Long.parseLong(parts[1].trim());
	    } catch (Exception e) {
		high = 0;
		return;
	    }
	}
	if (parts.length >= 3) {
	    try {
		low = Long.parseLong(parts[2].trim());
	    } catch (Exception e) {
		high = 0;
		low = 0;
		return;
	    }
	}

    }

    public static NNTPGroup fromName(String name) {
	return new NNTPGroup(name);
    }

    public String getName() {
	return name;
    }

    public long getFirstId() {
	return low;
    }

    public long getLastId() {
	return high;
    }

    public void reset() {
	low = 0;
	high = 0;
    }

    public void enter(String info) {
	if (info == null)
	    return;
	String[] parts = info.split(" ");

	if (parts.length >= 3) {
	    try {
		low = Long.parseLong(parts[2].trim());
		Log.d("NNTPGroup", "Low: " + low);
	    } catch (Exception e) {
		low = 0;
		return;
	    }
	}
	if (parts.length >= 4) {
	    try {
		high = Long.parseLong(parts[3].trim());
		Log.d("NNTPGroup", "high: " + high);
	    } catch (Exception e) {
		low = 0;
		high = 0;
		return;
	    }
	}
    }
};
